import { computed, onMounted, reactive } from 'vue'
import axios from 'axios'
 export default function(){
    // https://dog.ceo/api/breed/pembroke/images/random 获取图片接口
        let imagesList = reactive([
            'https://images.dog.ceo//breeds//pembroke//n02113023_6275.jpg'
        ])
        function getImage(){
            axios({
                url:'https://dog.ceo/api/breed/pembroke/images/random',
                method:'get'
            }).then(res=>{
                imagesList.push(res.data.message)
            }).catch(err=>{
                console.log(err)
                alert('请求失败',err.message)
            })
        }
        // hooks中也可以写钩子函数
        onMounted(() => {
            getImage()
        })
        // hooks中也可以写计算属性
        let count =  computed(()=>{
            return imagesList.length*10
        })
        //向外部提供数据
        return {imagesList,getImage,count}
 }